<template>
  <div class="video">
    <div class="videoinfo" v-for="item in videos" :key="item.vid" @click="toVideoPage(item.vid)">
      <div class="img">
        <img :src="item.coverUrl" />
        <div class="playTime"><i class="iconfont icon-playcircle"></i> {{ item.playTime >10000 ? (item.playTime / 10000).toFixed(0) + '万' : item.playTime }} </div>
        <span class="durations">{{ item.durationms }}</span>
      </div>
      <p class="title">
        <el-tag type="danger" size="mini" effect="plain" v-if="item.type === 0">MV</el-tag>
        <span>{{ item.title }}</span>
      </p>
      <div class="creator">
        <span v-for="(item1, index) in item.creator" :key="item1.userId">
          {{ index + 1 === item.creator.length ? item1.userName : item1.userName + ' / ' }}
        </span>
      </div>
    </div>
  </div>
</template>

<script>
import { getCloudSearch } from '../../network/search.js'
import { timeFormat } from '../common/util.js'
export default {
  props: ['type', 'value'],
  data () {
    return {
      videos: [],
      videoCount: 0
    }
  },
  methods: {
    // 播放页面
    toVideoPage (id) {
      this.$router.push('/video_player/' + id)
    },
    getCloudSearch (type, keywords) {
      getCloudSearch(type, keywords).then(res => {
        // console.log(res.data)
        if (res.data.result.videos) {
          res.data.result.videos.forEach(item => {
            item.durationms = timeFormat(item.durationms)
          })
        }
        this.videos = res.data.result.videos
        this.videoCount = res.data.result.videoCount
        this.$emit('singerCount', this.videoCount + ' 首专辑')
        // console.log(this.videos)
      })
    }
  },
  created () {
    this.getCloudSearch(this.type, this.value)
  },
  watch: {
    value (newVal, oldVal) {
      // console.log('新关键词:' + newVal)
      this.value = newVal
      this.getCloudSearch(this.type, this.value)
    }
  }
}
</script>

<style lang="less" scoped>
  .video {
    width: 100%;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    // justify-content: space-between;
    .videoinfo {
      width: 32%;
      margin: 5px 2% 15px 0;
      .img {
        position: relative;
        width: 100%;
        border-radius: 10px;
        overflow: hidden;
        img {
          width: 100%;
          height: ;
        }
        .playTime {
          position: absolute;
          top: 0;
          right:0;
          color: #fff;
          width: 100%;
          height: 5px;
          padding: 5px;
          text-align: right;
          background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.01));
        }
        .durations {
          position: absolute;
          bottom: 5px;
          right: 0;
          color: #fff;
          width: 100%;
          // height: 5px;
          padding: 5px;
          text-align: right;
          background-image: linear-gradient(to top, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.01));
        }
      }
      .title {
        font-size: 14px;
        text-align: left;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        span {
          margin-left: 5px;
        }
      }
      .creator {
        font-size: 14px;
        padding: 5px;
        color: #adadad;
      }
    }
    .videoinfo:nth-child(3n) {
      margin-right: 0;
    }
  }
</style>
